package com.NetSunWeiQin.chapter03.multithread4;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class AdminClient {
    public static void main(String args[]) {
        Socket socket = null;

        String command;
        String msg;

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            socket = new Socket("localhost", 8001);
            OutputStream socketOut = socket.getOutputStream();
            BufferedReader brSocket = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while (true) {

                command = br.readLine();

                socketOut.write((command+"\r\n").getBytes());

                msg = brSocket.readLine();
                if (msg!=null && msg.length() != 0){

                    System.out.println(msg);
                }



           /*     while ((msg = br.readLine()) != null) {
                    System.out.println(msg);
                    return;
                }*/

            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("网络连接中断.........");
        } finally {
            try {
                if (socket != null) socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

